package Object;

import com.sun.security.jgss.GSSUtil;

import java.util.Objects;

public class ObjectDemo1 {
    public static void main(String[] args) throws CloneNotSupportedException {
        //1.  toString
        Object obj = new Object();
        String str1 = obj.toString();
        System.out.println(str1);  //java.lang.Object@776ec8df

        //2.  equals
        String str2 = "123";
        String str3 = "123";
        StringBuilder sb = new StringBuilder("123");

        System.out.println(str2.equals(str3));//true

        System.out.println(str2.equals(sb));//false  原因 sb不是字符串而是StringBuilder
        System.out.println(sb.equals(str3));//false  原因 StringBuilder没有重写equals方法，采用的是Object中的equals方法比较的是地址值

        //3.  clone   浅克隆
        //3.1先创建一个对象
        User user1 = new User("张三","男",18);
        //3.2克隆对象
        //clone要在User当中进行重写才可以调用
        User user2 = (User) user1.clone();
        System.out.println(user1);
        System.out.println(user2);

        user2 = null;

        //4.  Objects
        //4.1  equals
        //自动判断空指针情况
        System.out.println(Objects.equals(user1, user2));
        //4.2  isNull
        //4.3  nonNull


    }
}
